//
//  LocationData.m
//  OAProject
//
//  Created by yhj on 2017/2/24.
//  Copyright © 2017年 cdnunion. All rights reserved.
//

#import "LocationData.h"
#import <CoreLocation/CoreLocation.h>

@interface LocationData ()<CLLocationManagerDelegate>

@property(nonatomic,strong)CLLocationManager *locationManager;

@property(nonatomic,strong)CLLocation *location;

@end

@implementation LocationData

//DEFINE_SINGLETON_FOR_CLASS(LocationData);

+(LocationData *)shareLocationData
{
    static LocationData *locationData=nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        locationData=[LocationData new];
    });
    return locationData;
}


//-(instancetype)init
//{
//    self=[super init];
//    if (self) {
//
//    }
//    return self;
//}

-(CLLocationManager *)locationManager
{
    if (!_locationManager) {
        _locationManager=[CLLocationManager new];
        _locationManager.delegate=self;
        _locationManager.distanceFilter=50;
        _locationManager.desiredAccuracy=kCLLocationAccuracyBestForNavigation;
        [_locationManager requestWhenInUseAuthorization];
    }
    return _locationManager;
}

-(void)start
{
    if ([CLLocationManager locationServicesEnabled]) {
        [self.locationManager startUpdatingLocation];
    }
}

-(void)stop
{
    [self.locationManager stopUpdatingLocation];
}

-(CGFloat)latitude
{
    return self.location.coordinate.latitude;
}


-(CGFloat)longitude
{
    return self.location.coordinate.longitude;
}

-(CGFloat)altitude
{
    return self.location.altitude;
}

//-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray<CLLocation *> *)locations
//{
//    self.location=[locations lastObject];
//
//    NSLog(@"纬度=%f，经度=%f， 海拔=%f", self.location.coordinate.latitude,
//          self.location.coordinate.longitude, self.location.altitude);
//    NSLog(@"%ld",(unsigned long)locations.count);
//
//    [API uploadLocationWithLongitude:[NSString stringWithFormat:@"%f",self.location.coordinate.longitude] latitude:[NSString stringWithFormat:@"%f",self.location.coordinate.longitude] altitude:[NSString stringWithFormat:@"%f",self.location.coordinate.longitude] success:^(BOOL is_success) {
//
//        NSLog(@"555---%hhd",is_success);
//
//    } failure:^(NSInteger stateCode) {
//
//    }];
//
//
//}


@end
